#include <iostream>
#include <ctime>
#include <algorithm>
#include <functional>
using namespace std;
int n;
int nums[100003];

void showNums() {
    for (int i = 0; i < n; i++) cout << nums[i] << " ";
    cout << endl;
}

int main() {
    srand((unsigned int)time(nullptr));
    cin >> n;
    for (int i = 0; i < n; i++) {
        nums[i] = rand() % 20;
    }
    showNums();
    make_heap(nums, nums+n);    // 默认是大根堆
    showNums();
    pop_heap(nums, nums+n);
    showNums();
    pop_heap(nums, nums+n-1);
    showNums();
    return 0;
}